﻿// add by king  2008-06-04


//----Add event to object
//----window.Load = OnBody_Load;
//----AddHandler(window, "load", "Load");    
      
function AddHandler(eventSource, eventName, handlerName, eventTarget)
{
	if (eventTarget == null)
		eventTarget = eventSource;
		
	if (eventSource.addEventListener)
	{
		eventSource.addEventListener(eventName, function(e) {eventTarget[handlerName](e);}, false);
	}
	else if (eventSource.attachEvent)
	{ 
		eventSource.attachEvent("on" + eventName, function(e) {eventTarget[handlerName](e);});
	}
	else
	{
		var originalHandler = eventSource["on" + eventName];
		
		if (originalHandler)
		{
			eventSource["on" + eventName] = function(e) {originalHandler(e); eventTarget[handlerName](e);};
		}
		else
		{
			eventSource["on" + eventName] = eventTarget[handlerName];
		}
	}
}

/*----------Show or hide object, you can show or hide mask div, the mask div is dynamic create*/
function Show(obj,ShowMask)
{
    if(obj)
        obj.style.display="";
    
    if(ShowMask)
    {
        ShowMaskDiv();
    }
}

function Hide(obj,HideMask)
{    
    if(obj)
        obj.style.display="none";
    
    if(HideMask)
        HideMaskDiv();
}

function ShowMaskDiv()
{
    Show(DivMaskObj(),false);
}

function HideMaskDiv()
{
    Hide(DivMaskObj(),false);
}

function DivMaskObj()
{
    var divId = "div_mask";
    CreateMaskDiv(divId)
    var divMaskObj = document.getElementById(divId);
    return divMaskObj;
}

function CreateMaskDiv(divId)
{
    /*    
    z-index:999;
    position:absolute;
    top:0px;
    left:0px;
    width:100%;
    height:100%;
    background-color:#fff;
    opacity:0.5;
    filter: alpha( opacity=50 ); 
    -moz-opacity: 0.5;
    */
    var divObj = document.getElementById(divId);
    if(!divObj)
    {
        try{
            var divObj = document.createElement("div");
            divObj.id = divId;
            divObj.className = "div_mask"; //depend on style of div_mask;
            divObj.zIndex = 100;
            divObj.style.display = "none";
            document.body.appendChild(divObj);
        }catch(e){alert(e);}
    }
    
    var scrollHeight = GetScrollHeight();
    var parentObj = divObj.parentNode;
    if(parentObj && parentObj.style.overflowY.toLowerCase()=="scroll")
    {
        scrollHeight = parentObj.scrollHeight;
    }
    divObj.style.height = scrollHeight+"px";    
}
function GetScrollHeight()
{
    var temp_h1 = document.body.scrollHeight;
    var temp_h2 = document.documentElement.scrollHeight;
    return temp_h1>temp_h2?temp_h1:temp_h2;    
}



function GetMoneySplit()
{
    if(typeof FormatNumber == undefined) FormatNumber="000 000 000";
    switch(FormatNumber)
    {
        case "000,000,000":
            return ","; //"000,000,000"
        case "000 000 000":
            return " ";//"000 000 000"
        default:
            return ",";
    }
}

function IntToMoney(nStr)
{
    var split = GetMoneySplit();
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + split + '$2');
    }
    return x1 + x2;
}

function MoneyToInt(v)
{
    v = v.replace(/,/g,"");
    v = v.replace(/ /g,"");
    return v;
}


function newWindow(url, name, w, h, resizable, scrollbars)
{
    window.open(url, name, 'width='+w+',height='+h+',scrollbars='+scrollbars+',resizable='+resizable+',toolbar=no');    
}